package com.lzw.bluetoothpractice.Activitys;

import android.content.Intent;
import android.os.Bundle;
import android.text.Html;
import android.text.method.ScrollingMovementMethod;
import android.util.Log;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.bumptech.glide.Glide;
import com.lzw.bluetoothpractice.AppConfig;
import com.lzw.bluetoothpractice.R;
import com.lzw.bluetoothpractice.Utils.AppUtil;
import com.lzw.bluetoothpractice.Utils.SharePreferenceUtils;
import com.lzw.bluetoothpractice.bean.HealthyMessageBean;
import com.lzw.bluetoothpractice.bean.HosptialBean;
import com.lzw.bluetoothpractice.network.HeadAssmblyUtils;
import com.lzw.bluetoothpractice.network.RetrofitManager;
import com.lzw.bluetoothpractice.network.api.RequestApi;

import java.util.Map;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

import static com.lzw.bluetoothpractice.MyApplication.getContext;

public class HosptialDetailActivity extends BaseActivity {
    private Map<String, String> keyMap;
    private  Intent intent;
    TextView hosptial_title;
    TextView hosptial_mesage;
    ImageView hosptial_pic;

    String hosptialId;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_hostptial_detail);
        intent=getIntent();
        hosptialId= intent.getStringExtra("hosptialId");

       // Log.e("article",article.toString());
        InitNavBar(true,"医院详情",false);
        InitView();
        InitData();


    }
    public void InitView(){
        hosptial_title=fd(R.id.hosptial_title);

        hosptial_mesage=fd(R.id.hosptial_mesage);

        hosptial_pic=fd(R.id.hosptial_pic);


    }
    public  void InitData(){
        try {
            keyMap = HeadAssmblyUtils.HeadAssembly("/dev-api/android/hospital/researchById");
        } catch (Exception e) {
            e.printStackTrace();
        }
        String accessToken = SharePreferenceUtils.getString(getContext(),"access_token",null);;
        RetrofitManager.getInstance(AppConfig.BASE_URL)
                .createReq(RequestApi.class).getHosptialDetail(Long.parseLong(hosptialId),"1", AppUtil.getVersionCode() + "", accessToken, keyMap.get("gmtStr"), keyMap.get("contentMD5"), keyMap.get("hmacCode")).
                observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()).subscribe(new Subscriber<JSONObject>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {

                Log.e("资讯详细查询",e.getMessage()+"");

            }

            @Override
            public void onNext(JSONObject json) {


                HosptialBean homeGridBean = JSON.parseObject(json.toString(), HosptialBean.class);
                if(homeGridBean.getCode()==200){


                    hosptial_title.setText(homeGridBean.getData().getHospitalName()+"");
                    hosptial_mesage.setText(homeGridBean.getData().getDescri()+"");
                    Glide.with(HosptialDetailActivity.this).load(AppConfig.BASE_URL+homeGridBean.getData().getPic()).into(hosptial_pic);



                }else {
                    Toast toast=Toast.makeText(HosptialDetailActivity.this,"查询医院详细信息失败",Toast.LENGTH_LONG);
                    toast.show();
                }


            }
        });



    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
       // isCltSatus=false;
      //  clt=false;
    }


}
